﻿using FangChanCrm.Services.Interface;
using Maticsoft.Model;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;

namespace FangChanCrm.Controllers
{
    public class PhoneGeRenController : Controller
    {
        private readonly It_RenYuanBiaoService t_RenYuanBiaoService;
        private readonly It_GangWeiBiaoService t_GangWeiBiaoService;
        public PhoneGeRenController(It_RenYuanBiaoService renYuanBiaoService, It_GangWeiBiaoService gangWeiBiaoService)
        {
            t_RenYuanBiaoService = renYuanBiaoService;
            t_GangWeiBiaoService = gangWeiBiaoService;
        }
        public IActionResult GeRenXinXi()
        {
            string mingcheng = "";
            string zhanghao = "";
            int gangweiid = 0;
            string gangwei = "";
            if (HttpContext.Session.GetString("loginid") != "" && HttpContext.Session.GetString("loginid") != null)
            {
                mingcheng = t_RenYuanBiaoService.GetById(Convert.ToInt32(HttpContext.Session.GetString("loginid"))).XingMing;
                zhanghao = t_RenYuanBiaoService.GetById(Convert.ToInt32(HttpContext.Session.GetString("loginid"))).ZhangHao;
                gangweiid = (int)t_RenYuanBiaoService.GetById(Convert.ToInt32(HttpContext.Session.GetString("loginid"))).t_GangWeiBiao.Id;
                gangwei = t_GangWeiBiaoService.GetById(gangweiid).GangWeiMingCheng;
            }
            ViewData["mingcheng"] = mingcheng;
            ViewData["zhanghao"] = zhanghao;
            ViewData["panduan"] = gangwei;
            return View();
        }
        public IActionResult ZhengZaiJianShe()
        {
            return View();
        }
        public string huiju()
        {
            int id = Convert.ToInt32(HttpContext.Session.GetString("loginid"));
            //int id = 5;
            //t_RenYuanBiao t_RenYuanBiao = t_RenYuanBiaoService.GetById(id);
            //string Json = "[{\"XingMing\":\"" + t_RenYuanBiao.XingMing + "\",\"ZhangHao\":\"" + t_RenYuanBiao.ZhangHao + "\"}]";
            List<t_RenYuanBiao> list2 = t_RenYuanBiaoService.GetList().Where(x => x.Id == id).ToList();
            for (int i = 0; i < list2.Count; i++)
            {
                list2[i].t_GangWeiBiao.t_RenYuanBiaos = null;
                list2[i].t_GangWeiBiao.t_BuMenBiao.t_GangWeiBiaos = null;
                list2[i].t_ZhanDuiBiao.t_RenYuanBiaos = null;
            }
            string Json = JsonConvert.SerializeObject(list2, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore });
            return Json;
        }
        public string touxiang()
        {
            int id = Convert.ToInt32(HttpContext.Session.GetString("UserId"));
            t_RenYuanBiao t_RenYuanBiao = t_RenYuanBiaoService.GetById(id);
            return t_RenYuanBiao.XingBie;
        }
    }
}
